package client.presentation;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;

import client.interactor.InteractorBehavior;

import com.sun.j3d.utils.universe.SimpleUniverse;

public class TwoDNavigator extends JPanel{

	private static final long serialVersionUID = -8697131155004085393L;

	private SimpleUniverse u;
	private InteractorBehavior interactor;

	public TwoDNavigator(InteractorBehavior i) {
		
		interactor = i;
		
		this.setLayout(new GridLayout(12,1));
		JButton zoomIn = new JButton("In");
		JButton zoomOut = new JButton("Out");
		JButton toLeft = new JButton("Left");
		JButton toRight = new JButton("Right");
		JButton toUp = new JButton("Up");
		JButton toDown = new JButton("Down");
		JButton toHLeft = new JButton("H Left");
		JButton toHRight = new JButton("H Right");
		JButton toPLeft = new JButton("P Left");
		JButton toPRight = new JButton("P Right");
		JButton toRLeft = new JButton("R Left");
		JButton toRRight = new JButton("R Right");
		zoomIn.addActionListener(new buttonZoomInListener());
		zoomOut.addActionListener(new buttonZoomOutListener());
		toLeft.addActionListener(new buttonLeftListener());
		toRight.addActionListener(new buttonRightListener());
		toUp.addActionListener(new buttonUpListener());
		toDown.addActionListener(new buttonDownListener());
		toHLeft.addActionListener(new buttonHLeftListener());
		toHRight.addActionListener(new buttonHRightListener());
		toPLeft.addActionListener(new buttonPLeftListener());
		toPRight.addActionListener(new buttonPRightListener());
		toRLeft.addActionListener(new buttonRLeftListener());
		toRRight.addActionListener(new buttonRRightListener());
		add(zoomIn);
		add(zoomOut);
		add(toLeft);
		add(toRight);
		add(toUp);
		add(toDown);
		add(toHLeft);
		add(toHRight);
		add(toPLeft);
		add(toPRight);
		add(toRLeft);
		add(toRRight);
		setSize(80,360);
	}

	public SimpleUniverse getU() {
		return u;
	}

	public void setU(SimpleUniverse u) {
		this.u = u;
	}

	class buttonZoomInListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(0, 0, -1);
		}

	}

	class buttonZoomOutListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(0, 0, 1);
		}

	}

	class buttonLeftListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(-1, 0, 0);
		}

	}
	class buttonRightListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(1, 0, 0);
		}

	}

	class buttonUpListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(0, 1, 0);
		}

	}

	class buttonDownListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.translateInLocal(0, -1, 0);
		}

	}

	class buttonHLeftListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(0.1, 0, 0);
		}

	}
	class buttonHRightListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(-0.1, 0, 0);
		}

	}

	class buttonPLeftListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(0, 0.1, 0);
		}

	}
	class buttonPRightListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(0, -0.1, 0);
		}

	}

	class buttonRLeftListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(0, 0, 0.1);
		}

	}
	class buttonRRightListener implements ActionListener {

		public void actionPerformed(ActionEvent e) {
			interactor.rotateInLocal(0, 0, -0.1);
		}

	}
}